//
//  NumberLineView.m
//  Teximeter
//
//  Created by BEA DONG HWAN on 11. 2. 7..
//  Copyright 2011 Ajou University. All rights reserved.
//

#import "NumberLineView.h"
#import "GraphicNumberView.h"

@implementation NumberLineView


- (id)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
		numberViewArray = [[NSMutableArray alloc]init];
		
		float totalWidth = frame.size.width;
		float dtWidth = totalWidth / 6.0f;
		float padding = 2.0f;
		float dtHeight = frame.size.height;
		
		for (int i=0; i<6; i++) {
			CGRect targetRect = CGRectMake(i*dtWidth+padding, 0, dtWidth-padding*2, dtHeight);
			GraphicNumberView* aView = [[GraphicNumberView alloc]initWithFrame:targetRect];
			[self addSubview:aView];
			[numberViewArray addObject:aView];
		}
    }
    return self;
}


-(void)setNumber:(int)target
{
	BOOL isFirst = YES;
	int last = target;
	for(int i=0;i<6;i++)
	{
		
		last = last%(int)(pow(10, 6-i));
		int result = last/(pow(10, 5-i));
		
		GraphicNumberView* aView = [numberViewArray objectAtIndex:i];
		[aView setCurrentNumber:result];
		if(isFirst && result==0)
		{
			[aView setCurrentNumber:-1];
		}
		if(isFirst && result!=0)
		{
			isFirst = NO;
		}
	}
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code.
}
*/

- (void)dealloc {
    [super dealloc];
}


@end
